import request from "request"
const appId = "uc1vkiikowpgvsjr"
const appSecret="eWQUU7W25QWacK9Lebd2e8mNbTlz0hBR"
export const getPuzzle = async (key) => {
    const url = `https://www.mxnzp.com/api/idiom/search?key=${key}&app_id=${appId}&app_secret=${appSecret}`
    var options = {
      'method': 'get',
      'url': encodeURI(url),
      'headers': {
        'Content-Type': 'application/json'
      },
    };
  
    return new Promise(async (resolve, roject) => {
      try {
        request(options, function (error, response) {
          if (error) resolve(error)
          resolve(response.body)
        })
        // const res = await chatGPTApi.sendMessage(message)
        // console.log('返回的消息')
        // console.log(res)
      } catch (e) {
        console.log("rollUp错误:")
        resolve(e)
      }
    })
  }

export const getPrettyPic= async ()=>{
    console.log('进入请求 开始')
    const url = `https://api.vvhan.com/api/wallpaper/pcGirl?type=json`
    var options = {
      'method': 'get',
      'url': encodeURI(url),
      'headers': {
        'Content-Type': 'application/json'
      },
    };
    return new Promise(async (resolve, roject) => {
      try {
        request(options, function (error, response) {

          if (error) resolve(error)
          resolve(response.body)
        })
      } catch (e) {
        console.log("rollUp错误:")
        resolve(e)
      }
    })
}

export const getBQ=({key,pageNum=1,pageSize})=>{
  console.log('表情关键:'+key)
  let url = `https://doutu.lccyy.com/doutu/items?keyword=${key}&pageNum=1&pageSize=${pageSize || 10}`
  var options = {
      'method': 'get',
      'url': encodeURI(url)
    }
    return new Promise((resolve,roject)=>{
      request(options, function (error, response, body) {
          // 如果请求成功且状态码为 200
          if (error){
              console.log(error)
              resolve(error)
              return
          }
          resolve(response.body )
        });
    })

}